/*
 * Copyright Groupe Adeo 2009
 * 
 * Licensed under New BSD License : http://www.opensource.org/licenses/bsd-license.php
 */
package com.adeoservices.gwt.dispatch.spring.server;

import net.customware.gwt.dispatch.server.Dispatch;
import net.customware.gwt.dispatch.shared.Action;
import net.customware.gwt.dispatch.shared.ActionException;
import net.customware.gwt.dispatch.shared.Result;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.adeoservices.gwt.dispatch.spring.client.SpringDispatchService;

/**
 * 
 * @author Olivier HEDIN / Adeo Services
 *
 */
@Service
public class SpringDispatchServiceImpl implements SpringDispatchService {
	
	private final Dispatch dispatch;
	
	@Autowired
	public SpringDispatchServiceImpl(Dispatch dispatch)
	{
		this.dispatch = dispatch;
	}

	@Override
	public Result execute(Action<?> action)
			throws ActionException {
	        try {
	            return dispatch.execute( action );
	        } catch ( RuntimeException e ) {
	            System.out.println( "Exception while executing " + action.getClass().getName() + ": " + e.getMessage() );
	            throw e;
	        }
	}

}
